﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IdentityModel.Tokens;
using System.ServiceModel.Security.Tokens;
using System.IdentityModel.Selectors;

namespace PSE.Framework.Common.Security.Services.Authentication.ClientCredentials
{
    public class TokenParameters : SecurityTokenParameters
    {
        public TokenParameters()
        {
        }

        protected TokenParameters(TokenParameters other)
            : base(other)
        {
        }

        protected override SecurityTokenParameters CloneCore()
        {
            return new TokenParameters(this);
        }

        protected override void InitializeSecurityTokenRequirement(SecurityTokenRequirement requirement)
        {
            requirement.TokenType = SecurityTokenTypes.UserName;
            return;
        }

        // A credit card token has no cryptography, no windows identity, and supports only client authentication.
        protected override bool HasAsymmetricKey { get { return false; } }

        protected override bool SupportsClientAuthentication { get { return true; } }

        protected override bool SupportsClientWindowsIdentity { get { return false; } }

        protected override bool SupportsServerAuthentication { get { return false; } }

        protected override SecurityKeyIdentifierClause CreateKeyIdentifierClause(SecurityToken token, SecurityTokenReferenceStyle referenceStyle)
        {
            if (referenceStyle == SecurityTokenReferenceStyle.Internal)
            {
                return token.CreateKeyIdentifierClause<LocalIdKeyIdentifierClause>();
            }
            else
            {
                throw new NotSupportedException("External references are not supported for bvmf tokens");
            }
        }
    }

}
